package com.zjjk.transfer.app;

import com.zjjk.transfer.source.entity.SourceOrder;
import com.zjjk.transfer.source.service.SourceOrderService;
import com.zjjk.transfer.target.entity.TargetOrder;
import com.zjjk.transfer.target.service.TargetOrderService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

@Component
public class OrderTransfer extends BaseTransfer<SourceOrder, TargetOrder, SourceOrderService, TargetOrderService> {
    
    @Override
    protected TargetOrder convert(SourceOrder source) {
        TargetOrder target = new TargetOrder();
        BeanUtils.copyProperties(source, target);
        target.setId(Long.valueOf(source.getId()));
        
        //待付款
        if (101 == source.getStatus()) {
            target.setStatus(0);
        }
        
        //配送中
        if (102 == source.getStatus()) {
            target.setStatus(10);
        }
        
        //已送达
        if (103 == source.getStatus()) {
            target.setStatus(15);
        }
        
        //已取消
        if (105 == source.getStatus()) {
            target.setStatus(30);
        }
        
        // 钱包支付
        if (source.getPayType() != null && source.getPayType().equals(301)) {
            target.setPayType(1);
        }
        
        // 微信小程序
        if (source.getPayType() != null && source.getPayType().equals(302)) {
            target.setPayType(2);
        }
        
        // 已支付
        if (2 == source.getPayStatus()) {
            target.setPayStatus(1);
        }else{
            target.setPayStatus(0);
        }
        
        if (source.getUserSex() == null) {
            target.setReceiverSex("未填写");
        }else if(source.getUserSex() == 2){
            target.setReceiverSex("女");
        }else {
            target.setReceiverSex("男");
        }
        target.setDeliveryMethod(1);
        target.setUserId(Long.valueOf(source.getUserId()));
        target.setReceiverName(source.getUserName());
        if (target.getReceiverName() == null) {
            target.setReceiverName("未填写");
        }
        target.setReceiverPhone(source.getUserPhone());
        if (target.getReceiverPhone() == null) {
            target.setReceiverPhone("未填写");
        }
        
        if (source.getUserAddress() == null) {
            target.setReceiverAddress("未填写");
        }else {
            target.setReceiverAddress(source.getUserAddress());
        }
        
        if (source.getDepartment() == null) {
            target.setReceiverDepartment("未填写");
        }else {
            target.setReceiverDepartment(source.getDepartment());
        }
       
        return target;
    }
    
}
